/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package shoppingClient;
    
import javax.swing.JFrame;

/**
 *
 * @author MinhDuc
 */
public class ProductInBuylistPanel extends javax.swing.JPanel {

    /**
     * Creates new form ProductInBuylistPanel
     */
    private Product product;
    private ShoppingClientGUI parentsFrame;
    
    public ProductInBuylistPanel(Product product,ShoppingClientGUI parents) {
        this.product = product;
        this.parentsFrame = parents;
        this.initComponents();
       
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        name = new javax.swing.JLabel();
        price = new javax.swing.JLabel();
        amount = new javax.swing.JLabel();
        avaiableAmount = new javax.swing.JLabel();
        removeButton = new javax.swing.JButton();

        setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED, new java.awt.Color(255, 0, 0), new java.awt.Color(0, 0, 255), null, null));
        setLayout(new java.awt.GridLayout(0, 1, 0, 10));

        name.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        name.setText(getNameofProduct());
        name.setToolTipText("");
        add(name);

        price.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        price.setText(getPriceLabel());
        add(price);
        price.getAccessibleContext().setAccessibleName("price");

        amount.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        amount.setText(getAmountLabel());
        add(amount);
        amount.getAccessibleContext().setAccessibleName("amount");

        avaiableAmount.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        avaiableAmount.setText(getAvaiableAmountLabel());
        add(avaiableAmount);

        removeButton.setText("Remove one item");
        removeButton.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                removeOneItem(evt);
            }
        });
        removeButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeButtonActionPerformed(evt);
            }
        });
        add(removeButton);

        getAccessibleContext().setAccessibleName("BuyListItem");
    }// </editor-fold>//GEN-END:initComponents

    private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_removeButtonActionPerformed

    private void removeOneItem(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_removeOneItem
        parentsFrame.removeOneItem(product.getName());
        this.validate();
    }//GEN-LAST:event_removeOneItem

    private String getNameofProduct(){
        return product.getName();
    }
    
    private String getPriceLabel(){
        StringBuilder bf = new StringBuilder();
        bf.append("price :");
        bf.append(product.getPrice());
        bf.append(" €");
        return bf.toString();
                
    }
    
    private String getAmountLabel(){
        StringBuilder bf = new StringBuilder();
        bf.append("amount in shopping cart :");
        bf.append(product.getAmount());
        return bf.toString();
    }
    
    private String getAvaiableAmountLabel(){
        StringBuilder bf = new StringBuilder();
        bf.append("avaiable amount in shop :");
        bf.append(product.getAvaiableAmount());
        return bf.toString();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel amount;
    private javax.swing.JLabel avaiableAmount;
    private javax.swing.JLabel name;
    private javax.swing.JLabel price;
    private javax.swing.JButton removeButton;
    // End of variables declaration//GEN-END:variables
}
